<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\pay\controller;

use cmf\controller\AdminBaseController;
use think\db\Query;
use think\facade\Db;

class ResourceController extends AdminBaseController
{

    /**
     * Notes:banner列表
     * User:
     * DateTime: 2022-01-17 14:57
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function banner()
    {
        $param = $this->request->param();
        $list = Db::name("slide_item")
            ->where(function (Query $query) use ($param) {
                $query->where('status', '=', 1);
                $query->where('slide_id', '<>', 3);
            })
            ->order("id desc")
            ->paginate(30);
        $page = $list->render();
        $this->assign("page", $page);
        $this->assign("list", $list);
        return $this->fetch();
    }

    /**
     * Notes:添加banner页面
     * User:
     * DateTime: 2022-01-17 16:53
     * @return mixed
     */
    public function addBanner()
    {
        return $this->fetch();
    }

    /**
     * Notes:执行添加banner
     * User:
     * DateTime: 2022-01-17 16:58
     */
    public function addPostBanner()
    {
        $param = $this->request->param();
        $data['slide_id'] = $param['slide_id'];
        $data['image'] = $param['image'];
        $res = Db::name("slide_item")->save($data);
        if (!$res) $this->error("失败！");
        $this->success("成功！");
    }

    /**
     * Notes:编辑banner页面
     * User:
     * DateTime: 2022-01-17 17:11
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function editBanner()
    {
        $param = $this->request->param();
        $info = Db::name("slide_item")->where(["id" => $param['id']])->find();
        $this->assign("info", $info);
        return $this->fetch();
    }

    /**
     * Notes:执行编辑banner
     * User:
     * DateTime: 2022-01-17 16:58
     */
    public function editPostBanner()
    {
        $param = $this->request->param();
        $data['slide_id'] = $param['slide_id'];
        $data['image'] = $param['image'];
        $res = Db::name("slide_item")->where(["id" => $param['id']])->save($data);
        if (!$res) $this->error("失败！");
        $this->success("成功！");
    }

    /**
     * Notes:删除
     * User:
     * DateTime: 2022-01-17 15:10
     * @throws \think\Exception
     */
    public function deleteBanner()
    {
        $id = $this->request->param('id', 0, 'intval');
        Db::name("slide_item")->where('id', $id)->delete();
        $this->success("删除成功");
    }

    /**
     * Notes:协议列表
     * User:
     * DateTime: 2022-01-17 14:57
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function agree()
    {
        $param = $this->request->param();
        $list = Db::name("articles")
            ->where(function (Query $query) use ($param) {
                $query->where(['status' => 1]);
            })
            ->order("id desc")
            ->paginate(30);
        $page = $list->render();
        $this->assign("page", $page);
        $this->assign("list", $list);
        return $this->fetch();
    }

    /**
     * Notes:添加协议页面
     * User:
     * DateTime: 2022-01-17 16:53
     * @return mixed
     */
    public function addAgree()
    {
        return $this->fetch();
    }

    /**
     * Notes:执行添加协议
     * User:
     * DateTime: 2022-01-17 16:58
     */
    public function addPostAgree()
    {
        $param = $this->request->param();
        $data['title'] = $param['title'];
        $data['content'] = $param['content'];
        $res = Db::name("articles")->save($data);
        if (!$res) $this->error("失败！");
        $this->success("成功！");
    }

    /**
     * Notes:编辑协议页面
     * User:
     * DateTime: 2022-01-17 17:11
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function editAgree()
    {
        $param = $this->request->param();
        $info = Db::name("articles")->where(["id" => $param['id']])->find();
        $this->assign("info", $info);
        return $this->fetch();
    }

    /**
     * Notes:执行编辑Agree
     * User:
     * DateTime: 2022-01-17 16:58
     */
    public function editPostAgree()
    {
        $param = $this->request->param();
        $data['title'] = $param['title'];
        $data['content'] = $param['content'];
        $res = Db::name("articles")->where(["id" => $param['id']])->save($data);
        if (!$res) $this->error("失败！");
        $this->success("成功！");
    }

    /**
     * 删除协议
     * @return void
     * @throws \think\db\exception\DbException
     */
    public function deleteAgree()
    {
        $id = $this->request->param('id', 0, 'intval');
        Db::name("articles")->where('id', $id)->delete();
        $this->success("删除成功");
    }

    /**
     * Notes:活动列表
     * User:
     * DateTime: 2022-01-17 14:57
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function active()
    {
        $param = $this->request->param();
        $list = Db::name("slide_item")
            ->where(function (Query $query) use ($param) {
                $query->where(['status' => 1]);
                $query->where(['slide_id' => 3]);
            })->order("id desc")
            ->paginate(30);
        $page = $list->render();
        $this->assign("page", $page);
        $this->assign("list", $list);
        return $this->fetch();
    }

    /**
     * Notes:添加活动页面
     * User:
     * DateTime: 2022-01-17 16:53
     * @return mixed
     */
    public function addActive()
    {
        return $this->fetch();
    }

    /**
     * Notes:执行添加活动
     * User:
     * DateTime: 2022-01-17 16:58
     */
    public function addPostActive()
    {
        $param = $this->request->param();
        $data['slide_id'] = 3;
        $data['title'] = $param['title'];
        $data['image'] = $param['image'];
        $data['content'] = $param['content'];
        $res = Db::name("slide_item")->save($data);
        if (!$res) $this->error("失败！");
        $this->success("成功！");
    }

    /**
     * Notes:编辑活动页面
     * User:
     * DateTime: 2022-01-17 17:11
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function editActive()
    {
        $param = $this->request->param();
        $info = Db::name("slide_item")->where(["id" => $param['id']])->find();
        $this->assign("info", $info);
        return $this->fetch();
    }

    /**
     * Notes:执行编辑活动
     * User:
     * DateTime: 2022-01-17 16:58
     */
    public function editPostActive()
    {
        $param = $this->request->param();
        $data['title'] = $param['title'];
        $data['image'] = $param['image'];
        $data['content'] = $param['content'];
        $res = Db::name("slide_item")->where(["id" => $param['id']])->save($data);
        if (!$res) $this->error("失败！");
        $this->success("成功！");
    }

    /**
     * Notes:活动删除
     * User:
     * DateTime: 2022-01-17 15:10
     * @throws \think\Exception
     */
    public function deleteActive()
    {
        $id = $this->request->param('id', 0, 'intval');
        Db::name("slide_item")->where('id', $id)->delete();
        $this->success("删除成功");
    }

}
